<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('还款计划') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('投资主体')" prop="investmentId">
        <el-select v-model="queryParams.investmentId" :placeholder="$t('投资主体')">
          <el-option
            v-for="investment in investmentList"
            :key="investment.id"
            :label="investment.investorName"
            :value="investment.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('还款类型')" prop="type">
        <dictSelect
          v-model="queryParams.type"
          :clearable="true"
          dictionary="servicing_plan_type"
        />
      </el-form-item>
      <el-form-item :label="$t('还款状态')" prop="status">
        <dictSelect
          v-model="queryParams.status"
          :clearable="true"
          dictionary="repayment_status"
        />
      </el-form-item>
      <el-form-item :label="$t('预计还款日期')" prop="expectDate">
        <DatePicker v-model="dateRange" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:plan:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['deal:plan:edit']"-->
      <!--          type="success"-->
      <!--          icon="el-icon-edit"-->
      <!--          size="mini"-->
      <!--          @click="lastExpectHandle"-->
      <!--        >{{ $t('维护最近还款计划') }}</el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:user:upload']"
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="upload.open = true"
        >{{ $t('导入') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :span-method="spanMethod" tooltip-effect="darkTable" :data="dealServicingPlanList" border>
      <!--      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">-->
      <!--        <template slot-scope="scope">-->
      <!--          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column :label="$t('投资主体')" align="center" prop="investmentName" min-width="180">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.investmentName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('还款类型')" align="center" prop="type" :formatter="typeFormat" width="130" />
      <el-table-column :label="$t('预计还款日期')" align="center" prop="expectDate" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('预计还款金额') + $t('金额单位')" align="center" prop="expectMoney" width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.expectMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实际还款日期')" align="center" prop="actualDate" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实际还款总额') + $t('金额单位')" align="center" prop="totalActualMoney" width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalActualMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实际还款金额') + $t('金额单位')" align="center" prop="actualMoney" width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.actualMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('还款状态')" align="center" prop="status" :formatter="statusFormat" width="130" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
        <template slot-scope="scope">
          <el-button
            v-if="!scope.row.status || scope.row.status === 'BFHK' || scope.row.status === 'WHK'"
            v-hasPermi="['deal:plan:edit']"
            size="small"
            type="text"
            icon="el-icon-money"
            @click="expectHandle(scope.row)"
          >{{ $t('还款') }}</el-button>
          <el-button
            v-if="!scope.row.status || scope.row.status === 'BFHK' || scope.row.status === 'WHK'"
            v-hasPermi="['deal:plan:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-if="!scope.row.status || scope.row.status === 'BFHK' || scope.row.status === 'WHK'"
            v-hasPermi="['deal:plan:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改还款计划明细对话框 -->
    <el-dialog v-if="formOpen" :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealServicingPlanForm ref="dealServicingPlanForm" />
    </el-dialog>
    <!-- 维护最近还款 -->
    <el-dialog :title="$t('维护最近还款计划(近30天未还款信息)')" :visible.sync="lastExpectOpen" :close-on-click-modal="false" width="75%" :lock-scroll="false" append-to-body>
      <div v-loading="lastExpectLoading">
        <el-form :inline="true">
          <el-table :data="lastExpectList" border class="nowrapTable formTable">
            <el-table-column :label="$t('投资主体')" align="center" prop="investmentName" />
            <el-table-column :label="$t('还款类型')" align="center" prop="type" :formatter="typeFormat" />
            <el-table-column :label="$t('预计还款日期')" align="center" prop="expectDate">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.expectDate) }}</span>
              </template>
            </el-table-column>
            <el-table-column :label="$t('预计还款金额') + $t('金额单位')" align="center" prop="expectMoney">
              <template slot-scope="scope">
                <span>{{ moneyFormat(scope.row.expectMoney, 'w') }}</span>
              </template>
            </el-table-column>
            <el-table-column :label="$t('实际还款日期')" align="center" prop="actualDate">
              <template slot-scope="scope">
                <DatePicker v-model="scope.row.actualDate" :placeholder="$t('实际还款日期')" />
              </template>
            </el-table-column>
            <el-table-column :label="$t('实际还款金额') + $t('金额单位')" align="center" prop="actualDate">
              <template slot-scope="scope">
                <Money v-model="scope.row.actualMoney" unit="w" :placeholder="$t('实际还款金额')" @change="lastActualMoney(scope.row)" />
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="lastExpectTotal>0"
            :total="lastExpectTotal"
            :page.sync="lastExpectParam.pageNum"
            :limit.sync="lastExpectParam.pageSize"
            @pagination="getLastExpectList"
          />
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: right;margin-top: 30px;">
          <!--保存，保存并启动流程，取消 三个按钮-->
          <el-button @click="lastExpectOpen = false">{{ $t("取消") }}</el-button>
          <el-button v-hasPermi="['deal:plan:edit']" type="primary" @click="lastExpectSubmit">{{ $t("保存") }}</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 还款 -->
    <el-dialog :title="$t('还款')" :visible.sync="expectOpen" :close-on-click-modal="false" :lock-scroll="false" width="80%" append-to-body>
      <el-form ref="expectForm" :model="expectForm" :inline="true" :rules="expectRules" class="dataForm expect">
        <el-table :data="expectForm.dealRepaymentList" tooltip-effect="darkTable" border>
          <el-table-column :label="$t('预计还款日期')" prop="estDate">
            <template slot-scope="scope">
              <el-form-item :prop="'dealRepaymentList.'+scope.$index + '.estDate'">
                <DatePicker v-model="scope.row.estDate" :disabled="true" :pick-options="options(scope.row)" :placeholder="$t('预计还款日期')" value-format="yyyy-MM-dd" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('预计还款金额') + $t('金额单位')" prop="estAmount">
            <template slot-scope="scope">
              <el-form-item :prop="'dealRepaymentList.'+scope.$index + '.estAmount'">
                <Money v-model="scope.row.estAmount" :disabled="true" unit="w" :placeholder="$t('预计还款金额')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('实际还款日期')" prop="actDate">
            <template slot-scope="scope">
              <el-form-item :prop="'dealRepaymentList.'+scope.$index + '.actDate'">
                <DatePicker v-model="scope.row.actDate" :clearable="false" :disabled="scope.row.disabled" :placeholder="$t('实际还款日期')" value-format="yyyy-MM-dd" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('实际还款金额') + $t('金额单位')" prop="actAmount">
            <template #header>
              <span style="color: red">*</span>
              <span>{{ $t('实际还款金额') + $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealRepaymentList.'+scope.$index + '.actAmount'" :rules="expectRules.actAmount">
                <Money v-model="scope.row.actAmount" :disabled="scope.row.disabled" unit="w" :placeholder="$t('实际还款金额')" />
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item :label="$t('预计还款日期')" prop="expectDate">-->
        <!--              <DatePicker v-model="expectForm.expectDate" :placeholder="$t('预计还款日期')" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item :label="$t('预计还款金额') + $t('金额单位')" prop="expectMoney">-->
        <!--              <money v-model="expectForm.expectMoney" unit="w" readonly />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item :label="$t('实际还款日期')" prop="actualDate">-->
        <!--              <DatePicker v-model="expectForm.actualDate" :placeholder="$t('实际还款日期')" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item :label="$t('实际还款金额') + $t('金额单位')" prop="actualMoney">-->
        <!--              <money v-model="expectForm.actualMoney" unit="w" :placeholder="$t('实际还款金额')" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: right;">
        <!--保存，保存并启动流程，取消 三个按钮-->
        <el-button @click="expectOpen = false">{{ $t("取消") }}</el-button>
        <el-button v-hasPermi="['deal:plan:edit']" type="primary" @click="expectSubmit">{{ $t("保存") }}</el-button>
      </div>
    </el-dialog>
    <!-- 导入窗口 -->
    <el-dialog :title="$t('导入')" :visible.sync="upload.open" width="400px" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
      <div>
        <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :on-exceed="handleFileExceed"
          :auto-upload="false"
          drag
        >
          <i class="el-icon-upload" />
          <div class="el-upload__text">
            {{ $t('将文件拖到此处，或') }}
            <em>{{ $t('点击上传') }}</em>
          </div>
          <div slot="tip" class="el-upload__tip" style="color:red">
            {{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}
            <el-link type="primary" style="font-size:12px" @click="fetchTemplate">
              {{ $t('下载模板') }}
            </el-link>
          </div>
        </el-upload>

        <div slot="footer" class="dialog-footer" style="text-align: right;">
          <el-button @click="upload.open = false">{{ $t("取消") }}</el-button>
          <el-button type="primary" @click="submitFileForm">{{ $t("确定") }}</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listDealServicingPlan,
  delDealServicingPlan,
  exportDealServicingPlan,
  saveDealServicingPlan,
  findLastThirtyDaysNotPlan,
  saveLastExpect
} from '@/api/deal/servicing/dealServicingPlan'
import dealServicingPlanForm from './dealServicingPlanForm.vue'
import { getToken } from '@/utils/auth'
import { listDealInvestment } from '@/api/deal/investment/dealInvestment'
import { listByServingId } from '@/api/deal/servicing/dealRepayment'
export default {
    components: {
        dealServicingPlanForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
        total: 0,
          // 还款计划明细表格数据
          dealServicingPlanList: [],
          // 维护最近还款
          lastExpectList: [],
          // 最近还款分页
          lastExpectParam: {
              pageNum: 1,
              pageSize: 10,
              dealId: this.$route.query.id
          },
          // 最近还款总条数
          lastExpectTotal: 0,
          // 维护最近还款弹出层
          lastExpectOpen: false,
          // 维护最近还款遮罩层
          lastExpectLoading: false,
          // 还款数据
          expectForm: {},
          // 还款弹出层
          expectOpen: false,
          // 弹出层标题
          title: '还款计划',
          // 是否显示弹出层
          formOpen: false,
          // 项目投资主体列表
          investmentList: [],
          // 还款状态
          statusOptions: [],
          // 还款类型字典
          typeOptions: [],
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              investmentId: undefined,
              type: undefined,
              expectDate: undefined,
              pageNum: 1,
              pageSize: 10
          },
        // 日期范围
        dateRange: [],
          // 表单参数
          form: {},
          publicPath: process.env.BASE_URL,
          // 还款计划导入参数
          upload: {
            // 是否显示弹出层（项目导入）
            open: false,
            // 弹出层标题（项目导入）
            title: '',
            // 是否禁用上传
            isUploading: false,
            // 设置上传的请求头部
            headers: { Authorization: 'Bearer ' + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + '/plan/dealServicingPlan/importData/' + this.$route.query.id
          },
          // 表单校验
          rules: {},
          expectRules: {
            actualDate: [
              { required: true, message: this.$t('必填信息'), trigger: 'blur' }
            ],
            actualMoney: [
              { required: true, message: this.$t('必填信息'), trigger: 'blur' }
            ],
            actAmount: [
              { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }
            ]
          }
      }
  },
  watch: {
    'expectForm.actualMoney': {
      handler(newVal) {
        debugger
        console.log(Number(newVal).toFixed(2))
        console.log(Number(this.expectForm.expectMoney).toFixed(2))
        if (newVal && Number(newVal).toFixed(2) > Number(this.expectForm.expectMoney).toFixed(2)) {
          this.expectForm.actualMoney = undefined
          this.msgError(this.$t('实际还款金额不能大于预计付款金额'))
        }
      }
    }
  },
  created() {
      this.getList()
      this.getDicts('servicing_plan_type').then(response => {
        this.typeOptions = response.data
      })
      listDealInvestment({ 'dealId': this.$route.query.id }).then(response => {
        this.investmentList = response.rows
      })
      // 还款状态字典
      this.getDicts('repayment_status').then(response => {
        this.statusOptions = response.data
      })
  },
  methods: {
      options() {
          return {
              disabledDate: (time) => {
                  var estTime = new Date(this.expectForm.expectDate).getTime()
                  if (estTime < new Date().getTime()) {
                      return time.getTime() < new Date().getTime() - 86400000
                  } else {
                      return time.getTime() < estTime - 86400000
                  }
              }
          }
      },
    /** 查询还款计划明细列表 */
    getList() {
        this.loading = true
        listDealServicingPlan(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.dealServicingPlanList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
        var columLabel = [this.$t('序号'), this.$t('实际还款总额') + this.$t('金额单位'), this.$t('预计还款日期'), this.$t('预计还款金额') + this.$t('金额单位'), this.$t('投资主体'), this.$t('还款类型'), this.$t('还款状态'), this.$t('操作')]
        console.log(row, rowIndex, column, columnIndex)
            if (row.equal) {
                if (columLabel.includes(column.label)) {
                    return [row.rowspan, 1]
                }
            } else {
                if (row.rowspan > 0 && columLabel.includes(column.label)) {
                    return [0, 0]
                }
            }
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: this.$route.query.id,
            investmentId: undefined,
            servicingId: undefined,
            type: undefined,
            expectDate: undefined,
            expectMoney: undefined,
            actualDate: undefined,
            actualMoney: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.dateRange = []
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealServicingPlanForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealServicingPlanForm.init(row)
        })
    },
    typeFormat(row) {
      return this.selectDictLabel(this.typeOptions, row.type)
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delDealServicingPlan(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportDealServicingPlan(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    },
    // 还款操作
    expectHandle(row) {
      this.expectOpen = true
      // 浅拷贝
      this.expectForm = Object.assign({}, row)
      listByServingId(row.id).then(res => {
          this.$set(this.expectForm, 'dealRepaymentList', [])
          var obj = null
        if (row.actualMoney && row.actualMoney > 0) {
          // obj = {
          //   id: undefined,
          //   sort: this.expectForm.dealRepaymentList.length + 1,
          //   estDate: row.expectDate,
          //   actDate: row.actualDate,
          //   estAmount: row.expectMoney,
          //   actAmount: row.actualMoney,
          //   disabled: true
          // }
          // this.expectForm.dealRepaymentList.push(obj)
          if (this.expectForm.dealRepaymentList.length > 0) {
            obj = {
              id: undefined,
              estDate: new Date().getTime() > new Date(row.expectDate).getTime() ? new Date() : row.expectDate,
              actDate: new Date(),
              estAmount: row.expectMoney - row.totalActualMoney,
              actAmount: undefined,
              disabled: false,
              sort: this.expectForm.dealRepaymentList.length + 1
            }
          } else {
            obj = {
              id: undefined,
              estDate: row.expectDate,
              actDate: new Date(),
              estAmount: row.expectMoney,
              actAmount: undefined,
              disabled: false,
              sort: this.expectForm.dealRepaymentList.length + 1
            }
          }
        } else {
          obj = {
            id: undefined,
            estDate: row.expectDate,
            actDate: new Date(),
            estAmount: row.expectMoney,
            actAmount: undefined,
            disabled: false,
            sort: this.expectForm.dealRepaymentList.length + 1
          }
        }
        if (res.rows) {
          console.log(res.rows, JSON.parse(JSON.stringify(this.expectForm.dealRepaymentList)), '666')
          res.rows.forEach(item => {
            this.$set(item, 'disabled', true)
            this.expectForm.dealRepaymentList.push(item)
          })
        }
          if (obj !== null && row.totalActualMoney < row.expectMoney) {
            console.log(this.expectForm.dealRepaymentList.length, '数组长度')
              obj.sort = this.expectForm.dealRepaymentList.length + 1
              this.expectForm.dealRepaymentList.push(obj)
          }
       })

      // if (this.expectForm.actualDate === null) {
      //   this.expectForm.actualDate = this.expectForm.expectDate
      // }
      // if (this.expectForm.actualMoney === null) {
      //   this.expectForm.actualMoney = this.expectForm.expectMoney
      // }
    },
    /** 还款 */
    expectSubmit: function() {
      this.$refs['expectForm'].validate(valid => {
        if (valid) {
          saveDealServicingPlan(this.expectForm).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.expectOpen = false
              this.getList()
            } else {
              this.msgError(response.msg)
            }
          })
        }
      })
    },
    // 维护最近还款计划
    lastExpectHandle() {
      this.lastExpectOpen = true
      this.getLastExpectList()
    },
    getLastExpectList() {
      this.lastExpectLoading = true
      findLastThirtyDaysNotPlan(this.lastExpectParam).then(response => {
        this.lastExpectList = response.rows
        this.lastExpectTotal = response.total
        this.lastExpectLoading = false
      })
    },
    lastExpectSubmit() {
      for (let i = 0; i < this.lastExpectList.length; i++) {
        if (this.lastExpectList[i].actualMoney > this.lastExpectList[i].expectMoney) {
          this.lastExpectList[i].actualMoney = undefined
          // this.$set(this.lastExpectList, i, this.lastExpectList[i])
          // this.msgError(this.$t('实际还款金额不能大于预计还款金额'))
          return
        }
      }
      this.lastExpectLoading = true
      saveLastExpect(this.lastExpectList).then(response => {
        if (response.code === 200) {
          this.msgSuccess(this.$t('保存成功'))
          this.lastExpectOpen = false
          this.lastExpectLoading = false
          this.getList()
        } else {
          this.msgError(response.msg)
          this.lastExpectOpen = false
          this.lastExpectLoading = false
        }
      })
    },
    // 文件上传中处理
    handleFileUploadProgress() {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      if (response.msg === 'success') {
        this.msgSuccess(this.$t('导入成功'))
      } else if (response.code === 500) {
        this.msgError(this.$t('数据异常'))
      } else {
        this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true })
      }
      // this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    // 文件达到上限处理
    handleFileExceed() {
      this.msgError(this.$t('可上传文件数量已达到上限'))
    },
    // 下载模板
    fetchTemplate() {
      var href1 = window.location.href
      var href2 = this.$route.path
      var url = href1.substring(0, href1.indexOf(href2))
      window.location.href = url + '/template/repayScheduletemplate.xlsx'
    },
    // 维护最近还款计划 实际还款金额change
    lastActualMoney(row) {
      if (row.actualMoney > row.expectMoney) {
        // this.$set(row, 'actualMoney', undefined)
        // this.msgError(this.$t('实际还款金额不能大于预计还款金额'))
      }
    },
    // 格式化收款状态
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status)
    }
  }
}
</script>
<style scoped lang="scss">
/deep/.expect {
  .el-form-item.is-error {
    min-height: 60px;
  }
}
</style>
